﻿
    using Maticsoft.BLL;
    using Maticsoft.Model;

    using System;
    using System.Text;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
using Utils;

    public partial class WebPage_ShangHu_Bianji : SystemBBasePage
    {

        private Maticsoft.BLL.Category category = new Maticsoft.BLL.Category();
        private Maticsoft.Model.Category categorymodel = new Maticsoft.Model.Category();

      
        private Maticsoft.BLL.Partner partner = new Maticsoft.BLL.Partner();
        private Maticsoft.Model.Partner patn = new Maticsoft.Model.Partner();

        private bool result = false;


        private void getContent(int id)
        {
            StringBuilder builder = new StringBuilder();
            StringBuilder builder2 = new StringBuilder();
            this.patn = this.partner.GetModel(id);
            if (this.patn != null)
            {
                ListItem item;
                this.categorymodel = this.category.GetModel(this.patn.City_id);
                if (this.categorymodel == null)
                {
                    item = new ListItem();
                    item.Value = "0";
                    item.Text = "全部城市";
                    item.Selected = true;
                    this.SelectOne.Items.Add(item);
                }
                else
                {
                    item = new ListItem();
                    item.Value = "0";
                    item.Text = "全部城市";
                    this.SelectOne.Items.Add(item);
                }
                foreach (Maticsoft.Model.Category category in this.category.GetModelList("Zone='city'"))
                {
                    ListItem item2 = new ListItem();
                    if (this.patn.City_id == category.Id)
                    {
                        item2.Value = category.Id.ToString();
                        item2.Text = category.Name.ToString();
                        item2.Selected = true;
                    }
                    else
                    {
                        item2.Value = category.Id.ToString();
                        item2.Text = category.Name.ToString();
                    }
                    this.SelectOne.Items.Add(item2);
                }
                ListItem item3 = new ListItem();
                item3.Value = "";
                item3.Text = "----选择分类----";
                this.SelectTwo.Items.Add(item3);
                foreach (Maticsoft.Model.Category category in this.category.GetModelList("Zone='partner'"))
                {
                    ListItem item4 = new ListItem();
                    if (this.patn.Group_id == category.Id)
                    {
                        item4.Value = category.Id.ToString();
                        item4.Text = category.Name;
                        item4.Selected = true;
                    }
                    else
                    {
                        item4.Value = category.Id.ToString();
                        item4.Text = category.Name;
                    }
                    this.SelectTwo.Items.Add(item4);
                }
                this.SelectOne.DataBind();
                this.SelectTwo.DataBind();
                this.Hidden1.Value = this.patn.Id.ToString();
                this.username.Value = this.patn.Username;
                this.shangwuxiu.Value = this.patn.Open;
                this.ImageSet.InnerText = this.patn.Image;
                if (this.patn.Image1 != "")
                {
                    this.hfimg1.Value = this.patn.Image1;
                    this.lblImg1.InnerHtml = string.Concat(new object[] { this.patn.Image1, "<span>&nbsp;&nbsp;</span><a href='ShangHu_Bianji.aspx?del=", this.patn.Id, "&image=1'>删除</a>" });
                }
                if (this.patn.Image2 != "")
                {
                    this.hfimg2.Value = this.patn.Image2;
                    this.lblImg2.InnerHtml = string.Concat(new object[] { this.patn.Image2, "<span>&nbsp;&nbsp;</span><a href='ShangHu_Bianji.aspx?del=", this.patn.Id, "&image=2'>删除</a>" });
                }
                this.shangwuMingcheng.Value = this.patn.Title;
                this.homepage.Value = this.patn.Homepage;
                this.contact.Value = this.patn.Contact;
                this.phone.Value = this.patn.Phone;
                this.address.Value = this.patn.Address;
                this.mobile.Value = this.patn.Mobile;
                this.location.Value = this.patn.Location;
                this.other.Value = this.patn.Other;
                this.bankname.Value = this.patn.Bank_name;
                this.bankno.Value = this.patn.Bank_no;
                this.bankuser.Value = this.patn.Bank_user;
                this.hdPwd.Value = this.patn.Password;
                this.hdUID.Value = this.patn.User_id.ToString();
                this.hdHead.Value = this.patn.Head.ToString();
            }
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.HeaderControl1.Select = "shanghu";
            if (base.Request.HttpMethod != "POST")
            {
                if (base.Request.QueryString["Id"] != null)
                {
                    this.getContent(int.Parse(base.Request.QueryString["Id"].ToString()));
                }
                if ((base.Request.QueryString["del"] != null) && (base.Request.QueryString["image"] != null))
                {
                    int id = int.Parse(base.Request.QueryString["del"].ToString());
                    int index = int.Parse(base.Request.QueryString["image"].ToString());
                    this.partner.UpdateImg(id, index);
                    base.SetSuccess("删除成功!");
                    base.Response.Redirect("ShangHu_Bianji.aspx?id=" + id);
                }
            }
        }

        protected void submit_ServerClick(object sender, EventArgs e)
        {
            string fileName;
            string str2;
            int num;
            string str3;
            string str4;
            Exception exception;
            Maticsoft.Model.Partner model = new Maticsoft.Model.Partner();
            model.Id = int.Parse(this.Hidden1.Value);
            if (this.SelectOne.SelectedItem.Value != "")
            {
                model.City_id = Convert.ToInt32(this.SelectOne.SelectedItem.Value);
            }
            if (this.SelectTwo.SelectedItem.Value != "")
            {
                model.Group_id = Convert.ToInt32(this.SelectTwo.SelectedItem.Value);
            }
            model.Username = this.username.Value;
            if (this.pwd.Value != "")
            {
                model.Password =  PassWord.MD5(this.pwd.Value);
            }
            else
            {
                model.Password = this.hdPwd.Value;
            }
            if (this.shangwuxiu.Value != string.Empty)
            {
                model.Open = this.shangwuxiu.Value.ToUpper();
            }
            else
            {
                model.Open = "N";
            }
            model.Title = this.shangwuMingcheng.Value;
            model.Homepage = this.homepage.Value;
            model.Contact = this.contact.Value;
            model.Phone = this.phone.Value;
            model.Address = this.address.Value;
            model.Mobile = this.mobile.Value;
            model.Location = this.location.Value;
            model.Other = this.other.Value;
            model.Bank_name = this.bankname.Value;
            model.Bank_no = this.bankno.Value;
            model.Bank_user = this.bankuser.Value;
            model.User_id = int.Parse(this.hdUID.Value);
            model.Head = int.Parse(this.hdHead.Value);
            if ((this.FileUpload1.FileName != null) && (this.FileUpload1.FileName.ToString() != ""))
            {
                if (this.FileUpload1.PostedFile.ContentLength > 0x7d000)
                {
                    this.SetError("请上传 512KB 以内的个人肖像图片!");
                    return;
                }
                fileName = this.FileUpload2.FileName;
                str2 = "";
                if (this.FileUpload2.FileName != "")
                {
                    num = fileName.LastIndexOf(".");
                    str3 = fileName.Substring(num);
                    str2 = DateTime.Now.Ticks.ToString() + 1 + str3;
                }
                try
                {
                    if (fileName != "")
                    {
                        str4 = base.Server.MapPath("~/upfile/user/");
                        this.FileUpload2.PostedFile.SaveAs(str4 + str2);
                    }
                }
                catch (Exception exception1)
                {
                    exception = exception1;
                    base.Response.Write(exception);
                }
                model.Image = "/upfile/user/" + str2;
            }
            else
            {
                model.Image = this.ImageSet.InnerText;
            }
            if ((this.FileUpload2.FileName != null) && (this.FileUpload2.FileName.ToString() != ""))
            {
                if (this.FileUpload2.PostedFile.ContentLength > 0x7d000)
                {
                    this.SetError("请上传 512KB 以内的个人肖像图片!");
                    return;
                }
                fileName = this.FileUpload2.FileName;
                string str5 = "";
                if (this.FileUpload2.FileName != "")
                {
                    num = fileName.LastIndexOf(".");
                    str3 = fileName.Substring(num);
                    str5 = DateTime.Now.Ticks.ToString() + 2 + str3;
                }
                try
                {
                    if (fileName != "")
                    {
                        str4 = base.Server.MapPath("~/upfile/user/");
                        this.FileUpload2.PostedFile.SaveAs(str4 + str5);
                    }
                }
                catch (Exception exception2)
                {
                    exception = exception2;
                    base.Response.Write(exception);
                }
                model.Image1 = "/upfile/user/" + str5;
            }
            else
            {
                model.Image1 = this.hfimg1.Value;
            }
            if ((this.FileUpload3.FileName != null) && (this.FileUpload3.FileName.ToString() != ""))
            {
                if (this.FileUpload3.PostedFile.ContentLength > 0x7d000)
                {
                    this.SetError("请上传 512KB 以内的个人肖像图片!");
                    return;
                }
                fileName = this.FileUpload3.FileName;
                str2 = "";
                if (this.FileUpload3.FileName != "")
                {
                    num = fileName.LastIndexOf(".");
                    str3 = fileName.Substring(num);
                    str2 = DateTime.Now.Ticks.ToString() + 3 + str3;
                }
                try
                {
                    if (fileName != "")
                    {
                        str4 = base.Server.MapPath("~/upfile/user/");
                        this.FileUpload3.PostedFile.SaveAs(str4 + str2);
                    }
                }
                catch (Exception exception3)
                {
                    exception = exception3;
                    base.Response.Write(exception);
                }
                model.Image2 = "/upfile/user/" + str2;
            }
            else
            {
                model.Image2 = this.hfimg2.Value;
            }
            this.partner.Update(model);
            base.SetSuccess("更新成功！");
            base.Response.Redirect("ShangHu_Bianji.aspx?Id=" + base.Request.QueryString["Id"].ToString(), true);
        }
    }


